package buttons.view;

import java.awt.Color;

import processing.core.PApplet;

public class V_DropDown extends V_TextButton
{
  protected V_PopUpMenu v_Options;
  protected String curOption = "";
  protected boolean showName = true;
  
  public V_DropDown(String n, float xWidth, float yHeight){
    super(n, xWidth, yHeight);
    this.setBGColor(new Color(255, 255, 255));
  }
  
  @Override
  public void display(PApplet p)
  {
    v_Options.setXLoc(this.getXLoc());
    v_Options.setYLoc(this.getYLoc()+this.getYSize());
    
    if(visible)
    { 
      int tmpColor = p.color(p.red(bgColor)+offset, p.green(bgColor)+offset, p.blue(bgColor)+offset, transp); 
      p.stroke(0,0,0,transp);
      p.fill(tmpColor);    
      p.rect(xLoc, yLoc, xSize, ySize);
      p.textFont(B_Font);
      p.fill(0,0,0,transp); 
      p.text(curOption, xLoc + 3, yLoc+fontSize);
      if(showName) p.text(name, xLoc - p.textWidth(name) - 5, yLoc+fontSize);
      p.fill(200,200,200,transp-100);
      
      float maxW = Math.min(xSize/5, 14);
      p.rect(xLoc+xSize-maxW, yLoc, maxW, ySize);
      p.fill(0,0,0,transp); 
      p.triangle(xLoc+xSize-2, yLoc + 3.5f,       xLoc+xSize-(maxW)+2, yLoc + 3.5f,      xLoc+xSize-(maxW/2), yLoc+ySize - 3.5f);
      v_Options.display(p); // Call to draw the expanded menu (it will only draw if set to be visible)
    }
  }
  
  public void addOptions(V_PopUpMenu vPopUp) {
    v_Options = vPopUp;
  }
  public void setCurOption(String val){
    curOption = val;
  }
  public String getCurOption(){
    return curOption;
  }
  public void setShowName(boolean val)
  {
    showName = val;
  }
}